//
//  ImageLabel.m
//  product_B
//
//  Created by zyc on 16/5/28.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "ImageLabel.h"

#import "ImageLabel.h"

@interface ImageLabel ()
@property (nonatomic, strong)UILabel *label;
@property (nonatomic, strong)UIImageView *imageView;
@end


@implementation ImageLabel

- (instancetype)initWithFrame:(CGRect)frame image:(UIImage *)image text:(NSString *)textString tapAction:(TapBlock)tapBlock{
    CGRect newFrame = frame;
    newFrame.size.height = newFrame.size
    .width/ 2;
    if (self = [super initWithFrame:newFrame]) {
        self.tapBlock = tapBlock;
        
        self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, newFrame.size.width / 2, newFrame.size.height)];
        if (image != nil) {
            _imageView.image = image;
        }
        [self addSubview:_imageView];
        
        
        self.label = [[UILabel alloc] initWithFrame:CGRectMake(newFrame.size.width / 2 + 2, 0, newFrame.size.width / 2 + 20, newFrame.size.height)];
        if (textString != nil) {
            _label.text = textString;
        }
        [self addSubview:_label];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        [self addGestureRecognizer:tap];
        _label.font = [UIFont fontWithName:@"Helvetica" size:12];
        
    }
    return self;
}

- (void)tapAction:(UITapGestureRecognizer *)tap {
    if (self.tapBlock) {
        self.tapBlock(_label, _imageView);
    }
    
}


- (void)setImageLabelText:(NSString *)text {
    _label.text = text;
}

- (void)setImageLabelImage:(UIImage *)image {
    _imageView.image = image;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
